Add log cache log streaming support#1338
Draft
ZPascal wants to merge 18 commits intocloudfoundry:mainfrom
Draft
Conversation
* because of the findFirst() on the envelopes, it could be type OUT or ERR, so we don't really care, as long as the payload is the same. Also, we don't care about the precise argument to the recentLogs call
The old "Applications.logs" method is keept for compatibility and when a log stream is needed. Adding new "logsRecent" method to access the logCache. integration-tests "ApplicationTest.logs" and "ApplicationTest.logsRecent" work. Minor changes in DefaultApplicationsTest in other JUnit tests to make them execute in Eclipse.
606817f to
08fb796
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds live log streaming via Log Cache to
cf-java-client– the Java equivalent ofcf tail --followand the Go [logcache.Walk()][go-walk] API.Previously, the only Log Cache read path was
logsRecent(a single snapshotGET /api/v1/read).There was no way to continuously stream new log envelopes without polling manually.
This change introduces a first-class
logsTailAPI across all three relevant modules(
cloudfoundry-client,cloudfoundry-client-reactor,cloudfoundry-operations).Motivation
Cloud Foundry dropped the legacy Loggregator Doppler streaming endpoint
(
DopplerClient.stream()) in Loggregator ≥ 107.0 (CFD ≥ 24.3 / TAS ≥ 4.0).The Go CF CLI replaced it with a polling loop over the Log Cache
[
/api/v1/read][log-cache-read] endpoint – that is whatcf tail --followdoes today.This PR brings the same capability to Java consumers.
Changes
Changes in detail
cloudfoundry-client— newTailLogsRequestvalue object andLogCacheClientAPINew file:
_TailLogsRequest.java(Immutables@Value.Immutable)sourceIdStringstartTimeLong(nullable)now − 5 s(ns)envelopeTypesList<EnvelopeType>(nullable)nameFilterString(nullable)pollIntervalDuration250 msLogCacheClientinterface — new method:cloudfoundry-client-reactor— non-blocking polling implementationReactorLogCacheEndpoints.logsTail()implements the walk loop fully non-blocking(no
Thread.sleep). The algorithm mirrors the Go [logcache.Walk()][go-walk]:AtomicLongstarts atstartTime(ornow − 5 s).Flux.deferbuilds a freshReadRequestfrom the current cursor on everyrepetition and calls
GET /api/v1/read/{sourceId}?start_time=cursor.lastTimestamp + 1; each envelope is emitted individually downstream.repeatWheninspects the per-cycle item count: when it is0(empty batch) a
Mono.delay(pollInterval)is inserted before the next poll;When envelopes are received, the next poll starts immediately.
Fluxis infinite; the caller cancels the subscription to stop.cloudfoundry-operations—Applications.logsTail()DefaultApplicationsimplements the newApplicationsinterface method by delegatingto
LogCacheClient:Applicationsinterface gains:Tests
Four unit tests cover
logsTailinDefaultApplicationsTest:logsTailLogCacheLOG/OUTenvelope is forwarded correctlylogsTailLogCacheMultipleEnvelopesOUT → ERR → OUTare all emitted in orderlogsTailLogCacheErrorRuntimeExceptionfrom the client propagates unchanged to the subscriberlogsTailLogCacheOutAndErrEnvelopesUsage Example
Or via the high-level Operations API:
Relation to existing API
DopplerClient.stream()LogCacheClient.recentLogs()LogCacheClient.logsTail()✅ newChecklist
_TailLogsRequestImmutables value objectLogCacheClient.logsTail()interface methodReactorLogCacheEndpoints.logsTail()— fully non-blocking Reactor implementation_ReactorLogCacheClient.logsTail()— delegate overrideApplications.logsTail()— high-level Operations API methodDefaultApplications.logsTail()— implementationlogsTailLogCacheinDefaultApplicationsTestDefaultApplicationsTesttests passNotes